home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / _xygraf.zip / GRAPHICS.TXT < prev    next >
Text File  |  1995-03-03  |  16KB  |  340 lines

  1. █████████████████████████████████████████████████████████████████████████████
  2. ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  3. ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ KNOW-HOW.GRAPHICS ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  4. ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  5. █████████████████████████████████████████████████████████████████████████████
  6.  
  7. This text contain brief description of KNOW_HOW.GRAPHICS 6.0x, the
  8. product in the 6th version of library. It provide the following features:
  9.     a) Using common code for any graphics library. It is realized now for
  10.        BGI and for Windows GDI. It is not difficult to add few lines of
  11.        code to use any other library, if it support basical operations
  12.        (lineto, moveto etc.)
  13.     b) Scrolling, Zooming, mirror reflection of image, rotations and even
  14.        complex rotations of image. Saying "complex rotations" I mean drawing
  15.        of the picture, rotated around x,y to alpha, then (result) around
  16.        x1,y1 to beta and so on. BGI fonts could be rotated too, filled BGI
  17.        fonts are also available (not all BGI font could be filled, of course).
  18. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  19. Additional (and very powerfull) features are available if KNOW-HOW.GRAPHICS
  20. is used together with KNOW-HOW.SLANG. SLANG is BASIC-like language, designed
  21. as CPP class. Its child classes could have additional operators, so
  22. KNOW-HOW.SLANG.GRAPHICS is the BASIC with access to drawing tools of current
  23. product. It provide to user the possibility to load graphical resourses
  24. (DOS or Windows, or other if he add some code) and interprete them in
  25. run-time. There are very many applications of this tool, like run-time
  26. changeable GUI, maketing (without stage of compilation) of BGI, GDI and so on
  27. applications, vector drawing tools (KNOW-HOW.VECTOR is the ready-to-use
  28. product of this type). Together with BASIC math. functions it could also be
  29. used for data plotting, spreadsheets and so on.
  30.  
  31. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  32. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ SERVICE FILES ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  33. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  34.  
  35. ▐▐▐▐▐▐▐ File SIMPLE.H contains some simplifications for often used names.
  36. Complete listing:
  37.  
  38. ▐ #ifndef __SIMPLE_H_
  39. ▐ #define __SIMPLE_H_
  40. ▐ typedef unsigned char uchar;
  41. ▐ typedef unsigned long ulong;
  42. ▐ typedef int bool;
  43. ▐ #define TRUE  1
  44. ▐ #define FALSE 0
  45. ▐ #define ON   TRUE
  46. ▐ #define OFF  FALSE
  47. ▐ #endif __SIMPLE_H_
  48. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  49. -----------------------------------------------------------------------------
  50. ▐▐▐▐▐▐▐ File GEOM.H contains geometry of KNOW-HOW. It defines geom. objects
  51. in C++ manner: loc(x, y) defines point, rect(x1, y1, x2, y2) - rectangle and
  52. so on.
  53. For example, instead of call to f(int x, int y) we could call f(loc l), where
  54. loc is defined in GEOM.H as
  55. ▐ struct loc
  56. ▐ { int X,Y;
  57. ▐ .....
  58. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  59. -----------------------------------------------------------------------------
  60. ▐▐▐▐▐▐▐ Files TRIGON.H and TRIGON.CPP contains structure with the overloaded
  61. sin(int) and cos(int) functions. This functions works much faster than standart
  62. versions but are not so flexible.
  63. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  64. -----------------------------------------------------------------------------
  65. ▐▐▐▐▐▐▐ Files KH_ERROR.H and KH_ERROR.CPP are the part of KNOW-HOW error
  66. handling system. The only variable is defined: kh_error_code. Functions of
  67. KNOW-HOW or user-defined functions could change it, default value is
  68. KH_SUCCESS:
  69.  
  70. ▐ enum { KH_SUCCESS, KH_UNKNOWN_ERROR, KH_FILE_ERROR, KH_BGI_ERROR,
  71. ▐       KH_MEMORY_ERROR, KH_USER_ERROR };
  72.  
  73. This list could be continued:
  74.  
  75. ▐ enum { KH_NEW_ERROR = KH_USER_ERROR + 1, ... }
  76. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  77. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ DRAWING MODULES ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  78. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  79.  
  80. ▐▐▐▐▐▐▐ File ABS_GRAF.H contains empty shablons of functions. We could
  81. derivate classes from it not thinking about concrete graphics library we
  82. shell use. It provide common code for any DOS, Windows and so on libraries,
  83. if them include the same functions. This set is only part of Paint class's
  84. functions set, described in PAINT.H:
  85.  
  86. ▐ struct AbstractGraphics
  87. ▐    {
  88. ▐    virtual void moveto(int x, int y) {}
  89. ▐    virtual void lineto(int x, int y) {}
  90. ▐    virtual void fillpoly(int numpoints, int* polypoints) {}
  91. ▐    };
  92. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  93. -----------------------------------------------------------------------------
  94. ▐▐▐▐▐▐▐ Files BGI_FONT.H and BGI_FONT.CPP contains class, which incapsulate
  95. BGI fonts (*.chr) description.
  96.     1. BGI fonts are not documented. I use existing format.
  97.     2. Abstract (non-BGI) graphics is used for moveto, lineto, drawpoly and
  98.        fillpoly operations. It should be overloaded in child classes for
  99.        concrete graf. libraries like BGI, Windows GDI and so on.
  100.     3. BGI header have some fields, which are not absolutely necessary (for
  101.        current class). I skip them and remarks are not complete for them.
  102. BGI font format is documented in the remarks to code in these files. So I
  103. give here only the brief explanation. BGI use two types of commands for
  104. drawing - moveto and lineto. To define non-filled fonts I use calls to the
  105. same (virtual) functions. To draw filled fonts I use fillpoly() function.
  106. In this case lineto calls are added to points array, and moveto call stop
  107. the polygon creation and begin next one. To use filled fonts you should
  108. use fonts which are drawn as group of closed polygons. Example - 'O' char:
  109.  
  110.        ┌───────┐
  111.        │▓▓▓▓▓▓▓│
  112.        │▓┌───┐▓│
  113.        │▓│   │▓│
  114.        │▓└─┬─┘▓│
  115.        │▓▓▓│▓▓▓│
  116.        └───┴───┘
  117. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  118. -----------------------------------------------------------------------------
  119. ▐▐▐▐▐▐▐ Files PAINT.H and PAINT.CPP. In the files described previously, we
  120. have incapsulated graphics primitives like lineto, moveto, drawchar and
  121. so on. Now the additional shell is included for rotation, mirror reflection,
  122. complex rotation, zooming and scrolling. All this operations are performed
  123. with abstract graphics calls, and not depend on library which you intend
  124. to use.
  125. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  126. ------------------------- WHAT IS COMPLEX ROTATION ? ------------------------
  127. ░Rotation could be simply processed if it is single operation. To use nested
  128. ░rotations we use stack of rotations info structures. Example of complex
  129. ░rotation:
  130. ░     void f1(int x, int y, int alpha) { ... perform rotation ... }
  131. ░     void f2(int x, int y, int alpha) { rotate(10,10,90); f1(x, y, alpha); }
  132. ░Function f2() call rotation procedure and then call f1(), which call another
  133. ░rotation. We could a) cancel first rotation and b) add first and second
  134. ░rotations to complex transformation. KNOW-HOW.GRAPHICS make possible both
  135. ░variances.
  136. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  137. The structure RInfo is used to keep information about single rotation, and
  138. stack of RInfo's is used (if R_STACK variable is set to 1) to keep complex
  139. rotation information.
  140. ▐ struct RInfo
  141. ▐    {
  142. ▐    loc center;
  143. ▐    int angle;
  144. ▐    };
  145. ///////////////
  146. ▐ struct Stack
  147. ▐    {
  148. ▐    int used, total;
  149. ▐    RInfo* list;
  150. ▐    Stack();
  151. ▐    ~Stack();
  152. ▐    void push(RInfo* r);
  153. ▐    void pop();
  154. ▐    void flash();
  155. ▐    };
  156. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  157. -----------------------------------------------------------------------------
  158. Class Paint give some additional facilities for any graphics library. Class
  159. does not contain calls to the concrete drawing functions - only to abstract
  160. prototypes.
  161. functions shold be overloaded in child classes for adaptation to concrete
  162. graphic interface (BGI, GDI, and so on).
  163.  
  164. The zoom and addzoom are deformation coeficients. You could use zoom in any
  165. part of program. Addzoom is used only once to set the additional deformation
  166. of the whole picture (for example if context is changed from screen to
  167. printer), for preview and so on.
  168.  
  169. ▐ class Paint : public BGI_Font
  170. ▐    {
  171. ▐    protected:
  172. ▐    loc zoom;                     // Image deformation
  173. ▐    loc add_zoom;                 // Additional deformation
  174. ▐    loc lt;                       // Scroll of part of picture
  175. ▐    loc add_scroll;               // Left - top clip of the whole picture
  176. ▐    int fill;                     // Fill flag
  177. ▐    loc center;                   // Rotation center
  178. ▐    int alpha;                    // Rotation angle
  179. ▐    bool R_STACK;                 // Use or not stack of rotations
  180. ▐    Stack* r_stack;               // Stack of rotations
  181. ▐    int mirror;
  182. ▐    public:
  183. ▐    Paint();
  184. ▐    ~Paint() { delete r_stack; }
  185. ▐    loc get_add_zoom() { return add_zoom; }
  186. ▐    loc get_zoom() { return zoom; }
  187. ▐    void set_mirror(int m) { mirror = m; } // X coord. if no rotation
  188. ▐    void set_stack(bool r) { R_STACK = r; r_stack->flash();
  189. ▐        rotate(loc(0, 0), 0); }
  190. ▐    void set_zoom(double x, double y) { zoom.X = x * add_zoom.X;
  191. ▐        zoom.Y = y * add_zoom.Y; }    // No out-of-range control !!!
  192. ▐    void set_add_zoom(double x, double y) { add_zoom.X = 100 * x;
  193. ▐        add_zoom.Y = 100 * y; }
  194. ▐    void set_scroll(int x, int y) { lt.X = x; lt.Y = y; }
  195. ▐    void set_add_scroll(int x, int y) { add_scroll.X = x;
  196. ▐        add_scroll.Y = y; }
  197. ▐    void rotate(loc c, int a);
  198. ▐    void set_fill(bool f) { fill = f; }
  199. ▐ // Using alpha and center returns rotated coordinates
  200. ▐    loc rot(int x, int y);
  201. ▐ // Return completely transformed point: rotated, zoomed and scrolled
  202. ▐    loc transform(int x, int y);
  203. ▐    };
  204. -----------------------------------------------------------------------------
  205. ▐▐▐▐▐▐▐ Files BGIPAINT.H and BGIPAINT.CPP. Classes in these files replace
  206. calls to empty graphics primitives functions to concrete calls of functions
  207. from BGI, GDI or from other drawing libraries. The #define directives set
  208. switches on one of libraries, user should unremark one of them to use it
  209. in program:
  210.  
  211. As the example, lets look to the code for DOS BGI.
  212.  
  213. ▐ #ifdef DOS_BGI           // If we define DOS_BGI 
  214. ▐ #include <graphics.h>    // Include GBI header
  215. The following structure do nonthing but replace calls to f() {} to calls
  216. to f() { ::f(); }, where ::f() is BGI function.
  217. ▐ struct To_Paint
  218. ▐     {
  219. ▐     void putpixel(int x, int y) { ::putpixel(x, y, getcolor()); }
  220. ▐     void line(int xstart, int ystart, int xend, int yend)
  221. ▐     { line(xstart, ystart, xend, yend); }
  222. ▐     void moveto(int x, int y) { ::moveto(x, y); }
  223. ▐     void lineto(int x, int y) { ::lineto(x, y); }
  224. ▐     void fillpoly(int numpoints, int* polypoints)
  225. ▐     { ::fillpoly(numpoints, polypoints); }
  226. ▐     void circle(int x, int y, int radius) { ::circle(x, y, radius); }
  227. ▐     void ellipse(int x, int y, int stangle, int endangle, int xr, int yr)
  228. ▐     { ::ellipse(x, y, stangle, endangle, xr, yr); }
  229. ▐     void drawpoly(int numpoints, int far* points)
  230. ▐     { ::drawpoly(numpoints, points); }
  231. ▐     };
  232. ▐ #endif DOS_BGI
  233.  
  234. Then we combine Paint class possibilities to zoom, scroll, rotate (including
  235. complex rotations) and so on and To_Paint possibilities to output graphics
  236. primitives using different libraries.
  237.  
  238. ▐ class KH_Paint : public To_Paint, public Paint
  239. ▐     {
  240. ▐     public:
  241. ▐     KH_Paint() : Paint()   {}
  242. ▐     void putpixel(int x, int y);
  243. ▐     void line(int xstart, int ystart, int xend, int yend);
  244. ▐     void lineto(int x, int y);
  245. ▐     void moveto(int x, int y);
  246. ▐     void circle(int x, int y, int radius);
  247. ▐     void ellipse(int x, int y, int stangle, int endangle, int xr, int yr);
  248. ▐     void roundrect(int left, int top, int right, int bottom, int radius);
  249. ▐     void rectangle(int left, int top, int right, int bottom);
  250. ▐     void drawpoly(int numpoints, int far* points);
  251. ▐     void outtext(char far* str);
  252. ▐     };
  253.  
  254. «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«
  255. ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ATTENTION !!! ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  256.     1. The set of functions of KH_Paint class will be continued, it is
  257. possible that your version contains additional functions (setcolor() is 
  258. already included, both (int color) and (Red, Green, Blue)).
  259.     2. When the Windows compatible part (class To_Paint for Windows) was
  260. designed, I find some difficulties: Windows GDI is more powerfull than DOS
  261. BGI. It is also possible that when user will try to use his graphics library
  262. he find that it have some functions which are absent in both BGI and GDI.
  263. The solution is: use KH_Paint functions if possible, I think that it is much
  264. more than enought for most cases. Another way is to add new functions to
  265. KH_Paint (KH_Paint::draw_pig() {...} and so on, and modify To_Paint for DOS
  266. and Windows), If it is not possible - use direct calls to your lovely library
  267. - and forget about the compatibility with others.
  268.     3. KH_Paint above is restricted. The real listing of 6.0 version (and of
  269. course of 6.x) is Windows GDI - oriented. It means that if BGI does not
  270. contain some of GDI features, DOS BGI version of To_Paint class try to
  271. elulate them.
  272. ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  273. «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«
  274. -----------------------------------------------------------------------------
  275. Example.
  276. I add to *.CPP files (when possible) working examples of main() functions,
  277. to run it you need only to remove remarks. In this file I illustrate only
  278. the usage of KNOW-HOW.GRAPHICS with DOS BGI, but BGIPAINT file contains
  279. also example of Windows OWL usage.
  280.  
  281. ▐ void main()
  282. ▐     {
  283. ▐     int gdriver = DETECT, gmode;           // Standart BGI initialization
  284. ▐     initgraph(&gdriver, &gmode, "");       // see Borland help system
  285. ▐     KH_Paint* paint = new KH_Paint();      // Create new KH_Paint class
  286. ▐     paint->load("euro.chr");               // Load BGI font
  287. ▐     setcolor(LIGHTRED);
  288. ▐     setfillstyle(SOLID_FILL, LIGHTGRAY);
  289. ▐     paint->set_fill(ON);                   // This flag acts on drawpoly
  290. ▐                        // but not to fonts filling.
  291. ▐     paint->set_zoom(0.5, 0.8);             // Set picture deformation
  292. ▐     for(int i = 0; i < 360; i += 15)       // BGI fonts output with rotation
  293. ▐     {
  294. ▐     paint->rotate(loc(400, 200), i);
  295. ▐     paint->outtextxy(10, 200, "Hello, World !");
  296. ▐     }
  297. ▐     cleardevice();
  298. ▐     for(int i1 = 0; i1 < 360; i1 += 15)    // Primitives output with rotation
  299. ▐     {
  300. ▐     paint->rotate(loc(400, 200), i1);
  301. ▐     paint->roundrect(300, 100, 400, 200, 20);
  302. ▐     int poly[10] = {100, 100, 200, 100, 200, 200, 100, 200, 100, 100};
  303. ▐     paint->drawpoly(5, poly);
  304. ▐     }
  305. ▐     cleardevice();
  306. ▐     paint->set_stack(ON);                  // Switch complex rotations ON
  307. ▐     for(i = 0; i < 360; i += 30)           // First call rotate image to 30,
  308. ▐     {                                  // second to 60 and so on.
  309. ▐     paint->rotate(loc(400, 200), 30);
  310. ▐     paint->outtextxy(10, 200, "Hello, World !");
  311. ▐     }
  312. ▐     paint->set_stack(OFF);
  313. ▐     for(int j = 0; j < 360; j += 15)
  314. ▐     {
  315. ▐     paint->rotate(loc(400, 200), j);            // Ellipse rotations
  316. ▐     paint->ellipse(200, 200, 0, 360, 30, 20);
  317. ▐     paint->ellipse(300, 200, 50, 120, 30, 20);
  318. ▐     }
  319. ▐     delete paint;
  320. ▐     closegraph();
  321. ▐     }
  322.